package control;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entity.Word;
import service.WordService;
import service.WordServiceimpl;

public class AddWord   extends HttpServlet{
	WordService wsc = new WordServiceimpl();
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		resp.setCharacterEncoding("Gbk");
		req.setCharacterEncoding("utf-8");
		String book = req.getParameter("book");
		String word = req.getParameter("word");
		String accent = req.getParameter("accent");
		String mean_cn = req.getParameter("mean_cn");
		String mean_en = req.getParameter("mean_en");
		String sentence = req.getParameter("sentence");
		String sentence_trans = req.getParameter("sentence_trans");
		String sentence_phrase = req.getParameter("sentence_phrase");
		String word_etyma = req.getParameter("word_etyma");

		Word wd = new Word(word, accent, mean_cn, mean_en, sentence, sentence_trans, sentence_phrase, word_etyma); 
		
		try {
			wsc.addword(book, wd);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		resp.getWriter().print("<script> alert(\"添加成功\");  window.history.back(-1); /* window.location.href=\"login&regist.html\" */;</script>");
		
	}
}
